/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package lintulaskenta.utils;

import javax.servlet.http.HttpServletResponse;

public class HttpRedirecter implements HttpRedirecterRajapinta {

	private final HttpServletResponse	res;
	private boolean hasBeenRedirected = false;

	public HttpRedirecter(HttpServletResponse res) {
		this.res = res;
	}

	@Override
	public void redirectTo(String uri) {
		res.setStatus(302);
		res.setHeader("Location", uri);
		res.setHeader("Connection", "close");
		hasBeenRedirected = true;
	}

	@Override
	public void redirectTo404() {
		res.setStatus(404);
		res.setHeader("Connection", "close");
		hasBeenRedirected = true;
	}

	@Override
	public void redirectTo500() {
		res.setStatus(500);
		res.setHeader("Connection", "close");
		hasBeenRedirected = true;
	}

	@Override
	public boolean hasBeenRedirected() {
		return hasBeenRedirected;
	}

}
